package com.education.upload.utils;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class UUIDUtils {
    public static String getByUUId() {
        int machineId = 1;//最大支持1-9个集群机器部署
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if (hashCodeV < 0) {//有可能是负数
            hashCodeV = -hashCodeV;
        }
        String idCode = machineId + (new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())) + hashCodeV;
        // 0 代表前面补充0
        // 15 代表长度为15
        // d 代表参数为正数型
        //System.out.println(idCode);
        return idCode;
    }

    public static String random32() {
        //try{
        //	Method method = Long.class.getDeclaredMethod("formatUnsignedLong0", long.class, int.class, byte[].class, int.class, int
        //	.class);
        //	method.setAccessible(true);
        //
        //	UUID uuid = UUID.randomUUID();
        //	long lsb = uuid.getLeastSignificantBits();
        //	long msb = uuid.getMostSignificantBits();
        //
        //	byte[] buf = new byte[32];
        //	method.invoke(Long.class, lsb, 4, buf, 20, 12);
        //	method.invoke(Long.class, lsb >>> 48, 4, buf, 16, 4);
        //	method.invoke(Long.class, msb, 4, buf, 12, 4);
        //	method.invoke(Long.class, msb >>> 16, 4, buf, 8,  4);
        //	method.invoke(Long.class, msb >>> 32, 4, buf, 0,  8);
        //	return new String(buf);
        //}catch (Throwable throwable){
        //	throw new BizException(BizMessage.SYSTEM_UUID_ERROR, throwable);
        //}
        String s = UUID.randomUUID().toString().replace("-", "");
        return s;
    }
}
